* Define shortcut to request file on PC which has cusips and edates. The edates 
are the fiscal year dates of firms listed on execucomp;
*To use this program you must have eventus and access to WRDS;
filename pcreqst 'C:\wald\return_input.txt';
/* Sign on to WRDS */
%let wrds = localhost 4016;
options comamid=TCP remote=WRDS;
options nocenter linesize=92;
signon username=_prompt_;
rsubmit;

/* Define shortcut to request file on WRDS Unix server. */
/* ~/ means use my home directory. */
/* File name need not be same on both systems. */
/* Make WRDS shortcut be request as expected by Eventus. */
filename request '~/demorequest.txt';
proc upload infile=pcreqst outfile=request; run;



/* Run the event study and create an output SAS data set. This will provide
the abnormal returns for each month of the 60 months following the edate. If
you set est = -1, then eventus will estimate the abnormal returns using estimation 
for 60 months to prior fiscal year end.  Need eventus manual to see how to change
the program for different estimation periods*/
Eventus monthly;
Request cusiperm autodate est=1   estlen=60  minestn=36;
Windows (1,1) (2,2) (3,3) (4,4) (5,5) (6,6) (7,7) (8,8) (9,9) (10,10)
(11,11) (12,12) (13,13) (14,14) (15,15) (16,16) (17,17) (18,18) (19,19) (20,20)
(21,21) (22,22) (23,23) (24,24) (25,25) (26,26) (27,27) (28,28) (29,29) (30,30)
(31,31) (32,32) (33,33) (34,34) (35,35) (36,36);
Evtstudy outsas=work.eventustemp both tail=2 patell stdcsect overlap pre=0 post=36 ;
/* Write CAR for selected windows to temp SAS data set democar.*/
Windows (1,1) (2,2) (3,3) (4,4) (5,5) (6,6) (7,7) (8,8) (9,9) (10,10)
(11,11) (12,12) (13,13) (14,14) (15,15) (16,16) (17,17) (18,18) (19,19) (20,20)
(21,21) (22,22) (23,23) (24,24) (25,25) (26,26) (27,27) (28,28) (29,29) (30,30)
(31,31) (32,32) (33,33) (34,34) (35,35) (36,36);
Extract insas=work.eventustemp outsas=work.democar;

data output;
set democar;

excess3 = (1+CAR_window_1)*(1+CAR_window_2)*(1+CAR_window_3);
excess12 = (1+CAR_window_1)*(1+CAR_window_2)*(1+CAR_window_3)*(1+CAR_window_4)*(1+CAR_window_5)* (1+CAR_window_6)*(1+CAR_window_7)*(1+CAR_window_8)*(1+CAR_window_9)*(1+CAR_window_10)*(1+CAR_window_11)*(1+CAR_window_12);
excess24 = excess12*(1+CAR_window_13)*(1+CAR_window_14)*(1+CAR_window_15)*(1+CAR_window_16)*(1+CAR_window_17)* (1+CAR_window_18)*(1+CAR_window_19)*(1+CAR_window_20)*(1+CAR_window_21)*(1+CAR_window_22)*(1+CAR_window_23)*(1+CAR_window_24);
excess36 = excess24*(1+CAR_window_25)*(1+CAR_window_26)*(1+CAR_window_27)*(1+CAR_window_28)*(1+CAR_window_29)* (1+CAR_window_30)*(1+CAR_window_31)*(1+CAR_window_32)*(1+CAR_window_33)*(1+CAR_window_34)*(1+CAR_window_35)*(1+CAR_window_36);
/* Copy democar from WRDS SAS work library to PC work library */
proc download data=output out="C:\wald\nexcessreturntest1a"; run;

/* End server statement block and close WRDS remote session. */
endrsubmit;
signoff;
